#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
火山云TOS配置类
包含TOS服务的所有配置参数
"""

import tos

class TOSConfig:
    """火山云TOS配置类"""
    
    def __init__(self):
        # TOS服务配置
        self.bucket_name = "aitogether-publicr-st"
        self.endpoint = "tos-cn-beijing.volces.com"
        self.access_key_id = "AKLTMDRjNzA2NDI0MzZjNDQ5MzkyZTI0YTM4OGE5MGE3ZTk"
        self.access_key_secret = "TldZMU56WXlZMk5rWWpOaE5HVTFNamhsT1dabU5qWTBNbUUzWW1Wak56WQ=="
        self.region = "cn-beijing"
        
        # CDN域名配置
        self.domain = "https://cdn-hs.yuaiweiwu.com/"
        
        # 文件路径前缀
        self.object_key_prefix = "aimath/elysium/"
        
        # 内网URL
        self.inner_url = "https://aitogether-publicr-st.tos-cn-beijing.ivolces.com"
        
        # CDN URL
        self.cdn_url = "https://cdn-hs.yuaiweiwu.com"
    
    def create_tos_client(self):
        """
        创建TOS客户端
        返回: TOS客户端实例
        """
        try:
            client = tos.TosClientV2(
                ak=self.access_key_id,
                sk=self.access_key_secret,
                endpoint=self.endpoint,
                region=self.region
            )
            return client
        except Exception as e:
            print(f"创建TOS客户端失败: {str(e)}")
            return None
    
    def get_full_object_key(self, file_name, custom_folder=None):
        """
        获取完整的对象键名
        参数:
            file_name: 文件名
            custom_folder: 自定义文件夹名（可选），将与基础路径组合
        返回:
            完整的对象键名
        """
        if custom_folder:
            # 清理自定义文件夹名，确保没有前后斜杠
            custom_folder = custom_folder.strip('/')
            return f"{self.object_key_prefix}{custom_folder}/{file_name}"
        else:
            return f"{self.object_key_prefix}{file_name}"
    
    def get_cdn_url(self, object_key):
        """
        获取CDN访问URL
        参数:
            object_key: 对象键名
        返回:
            CDN访问URL
        """
        return f"{self.cdn_url}/{object_key}" 